using Microsoft.AspNetCore.Mvc;
using JTZY.Model.Business.Dto;
using JTZY.Model.Business;
using JTZY.Service.Business.IBusinessService;
using JTZY.Admin.WebApi.Filters;

//创建时间：2024-12-27
namespace JTZY.Admin.WebApi.Controllers.Business
{
    /// <summary>
    /// stock
    /// </summary>
    [Verify]
    [Route("business/StockFlowItem")]
    public class StockFlowItemController : BaseController
    {
        /// <summary>
        /// stock接口
        /// </summary>
        private readonly IStockFlowItemService _StockFlowItemService;

        public StockFlowItemController(IStockFlowItemService StockFlowItemService)
        {
            _StockFlowItemService = StockFlowItemService;
        }

        /// <summary>
        /// 查询stock列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "stockflowitem:list")]
        public IActionResult QueryStockFlowItem([FromQuery] StockFlowItemQueryDto parm)
        {
            var response = _StockFlowItemService.GetList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询stock详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "stockflowitem:query")]
        public IActionResult GetStockFlowItem(long Id)
        {
            var response = _StockFlowItemService.GetInfo(Id);
            
            var info = response.Adapt<StockFlowItemDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加stock
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "stockflowitem:add")]
        [Log(Title = "stock", BusinessType = BusinessType.INSERT)]
        public IActionResult AddStockFlowItem([FromBody] StockFlowItemDto parm)
        {
            var modal = parm.Adapt<StockFlowItem>().ToCreate(HttpContext);

            var response = _StockFlowItemService.AddStockFlowItem(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新stock
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "stockflowitem:edit")]
        [Log(Title = "stock", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateStockFlowItem([FromBody] StockFlowItemDto parm)
        {
            var modal = parm.Adapt<StockFlowItem>().ToUpdate(HttpContext);
            var response = _StockFlowItemService.UpdateStockFlowItem(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除stock
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete/{ids}")]
        [ActionPermissionFilter(Permission = "stockflowitem:delete")]
        [Log(Title = "stock", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteStockFlowItem([FromRoute]string ids)
        {
            var idArr = Tools.SplitAndConvert<long>(ids);

            return ToResponse(_StockFlowItemService.Delete(idArr));
        }

    }
}